<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';

var game_deadline = '<?php echo $game_deadline ?>';

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getCityList',
    tbar:[{
        text:'添加',
        cls:'btn-show',
        handler:function() {
            var win = new ZM.PopUp({
                title:'添加时间设置',
                defaults:{labelWidth: 120},
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/createCity',
                    success:function(res) {
                        ZM.bo.msg('success',res.detail);
                        list.grid.store.reload();
                        win.close();
                    },
                    items:[{
                        fieldLabel:'城市',
                        name:'city_name',
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'总金额',
                        name:'city_total_money',
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'红包金额',
                        name:'city_person_money',
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                       	fieldLabel:'游戏时间(s)',
                        name:'city_time',
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'至少点击次数',
                        name:'city_click_limit',
                        allowBlank:false
                    }]
                }
            }).show();
        }
    },'-',{
        xtype:'displayfield',
        id:'deadline_time',
        value: '结束时间: '+(game_deadline ? game_deadline : '无')
    },'-',{
        text:'设置结束时间',
        cls:'btn-show',
        handler:function() {
            var win = new ZM.PopUp({
                title:'添加时间设置',
                type:'s',
                defaults:{labelWidth: 120},
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/setGameDeadline',
                    success:function(res) {
                        ZM.bo.msg('success',res.detail);
                        game_deadline = Ext.getCmp('set_game_deadline').getValue();
                        Ext.getCmp('deadline_time').setValue('结束时间: ' + game_deadline);
                        win.close();
                    },
                    items:[{
                        xtype:'datetimefield',
                        id:'set_game_deadline',
                        name:'<?php echo HD_OIL_SUBSIDY_DEADLINE ?>',
                        value:game_deadline,
                        fieldLabel:'结束时间'
                    }]
                }
            }).show();
        }
    }],
    columns:[
        {header:'ID',dataIndex:'lottery_time_id',hidden:true},
        {header:'城市',dataIndex:'city_name'},
        {header:'总金额',dataIndex:'city_total_money'},
        {header:'个人获奖红包',dataIndex:'city_person_money'},
        {header:'游戏时间',dataIndex:'city_time'},
        {header:'需要点击次数',dataIndex:'city_click_limit'},
		{header:'状态',dataIndex:'city_status',width:65,renderer:function(val) {
           return ZM.status(val);
        },filter:{
            xtype:'combofield',
            options:[['','全部'],['-1','禁用'],['1','激活']]
        }},
        {header:'创建时间',dataIndex:'city_time_create',width:140},
        {header:'最后修改时间',dataIndex:'city_time_lastmodified',width:140},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            str += Ext.rd('编辑','fireEdit',r,attr.ctrlName+'/editCity');
            if(r.json.city_status == 1) {
            	str += Ext.rd('禁用','fireDisable',r,attr.ctrlName+'/disableCity');
            } else {
            	str += Ext.rd('激活','fireActive',r,attr.ctrlName+'/activeCity');
            }
            
            return str;
        }}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireEdit = function(r) {
    var r = r.json;
    var win = new ZM.PopUp({
        title:'添加时间设置',
        defaults:{labelWidth: 120},
        items:{
            xtype:'formpanel',
            url:list.baseUrl+ attr.ctrlName+'/editCity',
            success:function(res) {
                ZM.bo.msg('success',res.detail);
                list.grid.store.reload();
                win.close();
            },
            params:{lottery_time_id:r.lottery_time_id},
            items:[{
                fieldLabel:'城市',
                        name:'city_name',
                        value: r.city_name,
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'总金额',
                        name:'city_total_money',
                        value: r.city_total_money,
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'红包金额',
                        name:'city_person_money',
                        value: r.city_person_money,
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                       	fieldLabel:'游戏时间(s)',
                        name:'city_time',
                        value: r.city_time,
                        allowBlank:false
                    },{
                    	xtype:'numberfield',
                        fieldLabel:'至少点击次数',
                        name:'city_click_limit',
                        value: r.city_click_limit,
                        allowBlank:false
            }]
        }
    }).show();
}

list.grid.fireDisable = function(r) {
    var r = r.json;
    ZM.ajax({
        url: list.baseUrl + attr.ctrlName+'/disableCity',
        params:{city_id:r.city_id},
        mask:list.grid,
        success:function(res){
            ZM.bo.msg('success',res.detail);
            list.grid.store.reload();
        }
    });
}

list.grid.fireActive = function(r) {
    var r = r.json;
    ZM.ajax({
        url: list.baseUrl + attr.ctrlName+'/activeCity',
        params:{city_id:r.city_id},
        mask:list.grid,
        success:function(res){
            ZM.bo.msg('success',res.detail);
            list.grid.store.reload();
        }
    });
}


<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>